<template>
  <!-- 版本一:自己的结构 -->
  <!-- 容器 -->
  <!-- <div class="goodsDetail">
  面包屑
  <XtxBread>
      <XtxBreadItem to="/">首页</XtxBreadItem>
      <XtxBreadItem to="/">数码</XtxBreadItem>
      <XtxBreadItem to="/">车载用品</XtxBreadItem>
      <XtxBreadItem to="/">网易智造三合一</XtxBreadItem>
    </XtxBread> -->
  <!-- 商品信息 -->
  <!-- 商品信息:左=> 图片展示+销售统计信息-->
  <!-- 商品信息:右=> 商品介绍,参数,规格,数量,addCart组件-->
  <!-- <div class="goodsInfo">
  <div class="left">
     图片展示
    <XtxImageView></XtxImageView>
    <销售统计信息
  </div>
<div class="right">
    商品介绍

 参数规格
  数量
 加入购物车
  </div>
</div> -->
  <!-- 同类推荐 -->
  <!-- <div class="goodsRelevant">
      猜你喜欢
    </div> -->
  <!-- 商品详情
   商品详情=>1:商品参数
   商品详情=>2:商品评价
   商品详情=>3:24h热榜+同类推荐 -->
  <!-- <div class="goodsInfoDetail">
      <div class="goodsRefs">商品参数</div>
      <div class="comments">评价</div>
      <div class="hotList">
        24h热榜+同类推荐
      </div>
    </div>
  </div>-->
  <!-- 版本二:嫖来的结构 -->
  <div class="goodsDetail">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem to="/">手机</XtxBreadItem>
        <XtxBreadItem to="/">华为</XtxBreadItem>
        <XtxBreadItem to="/">p30</XtxBreadItem>
      </XtxBread>

      <!-- 商品信息 -->
      <div class="goods-info">
        <!--左边-->
        <div class="media">
          <!-- 区域1 商品图片组件 -->
          <!-- 向子组件传入主图地址集合 -->
          <XtxImageView :imageList="goods?.mainPictures"></XtxImageView>
          <!-- 区域2 商品销售信息组件 -->
          <goodSaleInfo :goodsData="goods"></goodSaleInfo>
        </div>
        <!--右边-->
        <div class="spec">
          <!-- 区域3 商品介绍组件 -->
          <goodInfo :goodsData="goods"></goodInfo>
          <!-- 区域4 商品规格组件  -->
          <!-- 全局组件Sku -->
          <XtxGoodSku :goods="goods"></XtxGoodSku>
          <!-- 区域5 数量选择组件 -->
          <numBox v-model="num"></numBox>
          <!-- 加入购物车 按钮 -->
          <XtxButton type="primary" class="addCart">addCart</XtxButton>
        </div>
      </div>
      <!-- 商品推荐 -->
      <div class='goods-relevant'>
        商品推荐
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <goodRefs :goods="goods"></goodRefs>
          <!-- 注意事项 -->
          <div class="goods-warn">商品+评价</div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside">
          <goodHot :type="1"></goodHot>
           <goodHot :type="2"></goodHot>
            <goodHot :type="3"></goodHot>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 按需导入方法
import { goodsDetail } from '@/api/goods/index.js'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
// 导入子组件
import goodInfo from './components/goodInfo.vue'
import goodSaleInfo from './components/goodSaleInfo.vue'
import goodRefs from './components/goodRefs.vue'
import goodHot from './components/goodHot.vue'
export default {
  name: 'goodsDetail',
  components: { goodInfo, goodSaleInfo, goodRefs, goodHot },
  setup () {
    // 1:设置初始商品数据
    const goods = ref({})
    const route = useRoute()
    // 设置数量初始值
    const num = ref(1)
    // 请求商品详情页的相关数据
    // 传递参数:商品id,上一轮刚完成的额商品点击路由携带参数的修改为本步骤铺垫
    async function loadGoodsDetail () {
      const res = await goodsDetail(route.params.id)
      console.log(res, '我是商品相亲数据')
      goods.value = res.result
    }
    loadGoodsDetail()
    return {
      goods,
      num
    }
  }
}
</script>

<style lang="less" scoped>
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    position: relative;
    flex: 1;
    padding: 30px 30px 30px 0;
    .addCart {
      position: absolute;
      left: 0;
      margin-top: 20px;
    }
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}

.number-box {
  display: flex;
  align-items: center;
  .label {
    width: 60px;
    color: #999;
    padding-left: 10px;
  }
}
.g-name {
  font-size: 22px;
}
.g-desc {
  color: #999;
  margin-top: 10px;
}
.g-price {
  margin-top: 10px;
  span {
    &::before {
      content: '¥';
      font-size: 14px;
    }
    &:first-child {
      color: @priceColor;
      margin-right: 10px;
      font-size: 22px;
    }
    &:last-child {
      color: #999;
      text-decoration: line-through;
      font-size: 16px;
    }
  }
}
.g-service {
  background: #f5f5f5;
  width: 500px;
  padding: 20px 10px 0 10px;
  margin-top: 10px;
  dl {
    padding-bottom: 20px;
    display: flex;
    align-items: center;
    dt {
      width: 50px;
      color: #999;
    }
    dd {
      color: #666;
      &:last-child {
        span {
          margin-right: 10px;
          &::before {
            content: '•';
            color: @xtxColor;
            margin-right: 2px;
          }
        }
        a {
          color: @xtxColor;
        }
      }
    }
  }
}
.goods-sales {
  display: flex;
  width: 400px;
  align-items: center;
  text-align: center;
  height: 140px;
  li {
    flex: 1;
    position: relative;
    ~ li::after {
      position: absolute;
      top: 10px;
      left: 0;
      height: 60px;
      border-left: 1px solid #e4e4e4;
      content: '';
    }
    p {
      &:first-child {
        color: #999;
      }
      &:nth-child(2) {
        color: @priceColor;
        margin-top: 10px;
      }
      &:last-child {
        color: #666;
        margin-top: 10px;
        i {
          color: @xtxColor;
          font-size: 14px;
          margin-right: 2px;
        }
        &:hover {
          color: @xtxColor;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
